package com.stylefeng.guns.spider.Pipeline;

import com.alibaba.fastjson.JSONObject;
import com.stylefeng.guns.modular.system.dao.SecondaryInfoMapper;
import com.stylefeng.guns.modular.system.model.SecondaryInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

import java.util.Map;

@Component("LianJiaPipeline")
public class LianJiaPipeline implements Pipeline {

    @Autowired
    private SecondaryInfoMapper secondaryInfoMapper;

//	@Override
//	public void process(DouyuLolInfo t, Task task) {
//
//		System.out.println(t.getTitle());
//		//douyuMapper.insertSelective(t);
//	}

    @Override
    public void process(ResultItems resultItems, Task task) {
        Map<String, Object> map = resultItems.getAll();
        SecondaryInfo secondaryInfo = JSONObject.parseObject(JSONObject.toJSONString(map), SecondaryInfo.class);
        if(secondaryInfo != null && secondaryInfo.getTitle() != null){
            secondaryInfoMapper.insert(secondaryInfo);
        }
    }

}
